<?php
  include ('header.php');
  require_once('includes/db_connect.inc.php');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php echo $titles['inv_card_n1'] ?></title>	

</head>


<body>
<?php 
	if (isset($_POST['inv_numb_filter'])){
	$_SESSION['inv_numb_filter']=$_POST['inv_numb_filter'];
	} 
	if (isset($_POST['name_filter'])){
	$_SESSION['name_filter']=$_POST['name_filter'];
	} 

	if (isset($_POST['auditory'])){
	$_SESSION['auditory']=$_POST['auditory'];
	} 
	
	if (isset($_POST['status'])){
	$_SESSION['status']=$_POST['status'];
	} 
	?>
<form  method="POST" name='inv_card1'>
<TABLE  class="inv_card1" width='90%'>
<TR ><td width=20>

<a href="excel_export.php"><img src='images/excel.png' border=0  width=25 height=25 alt='Экспорт в excel'></a>
</td></tr><tr>
<td align="left"  colspan=8 width='*'>
Фільтри: по назві: <input type="text" name="name_filter" size=20  onchange='document.forms["inv_card1"].submit();' value="<?php echo $_SESSION['name_filter']?>">
по інв. номеру: <input type="text" name="inv_numb_filter" size=8  onchange='document.forms["inv_card1"].submit();' value="<?php echo $_SESSION['inv_numb_filter']?>">
по аудиторії: 
<SELECT NAME="auditory" onchange='document.forms["inv_card1"].submit();'>
<?php 
$sql2="SELECT * FROM auditories order by auditory_id";  
$process2=mysql_query($sql2, $db);
$i=1;
while ($row2 = mysql_fetch_array($process2, $i)){
$selected=($row2[auditory_id]==$_SESSION['auditory']) ? ' selected' :'';
echo "<option value='".$row2[auditory_id]."' ".$selected.">".$row2[auditory_name]."</option>";
}
?>
</SELECT>

	по статусу: 
<SELECT NAME="status" onchange='document.forms["inv_card1"].submit();'>
<?php 
$sql2="SELECT * FROM item_status order by status_id";  
$process2=mysql_query($sql2, $db);
$i=1;
while ($row2 = mysql_fetch_array($process2, $i)){
$selected=($row2[status_id]==$_SESSION['status']) ? ' selected' :'';
echo "<option value='".$row2[status_id]."' ".$selected.">".$row2[status_name]."</option>";
}
?>
</SELECT>

</td>
</TR >
<TR >
	<td class="inv_card1" width='20' > № Ауд</td>
	<td class="inv_card1" width='50' > Інв номер</td>
	<td class="inv_card1" width='200' > Найменування цінностей (по бухг)</td>
	<td class="inv_card1" width='40' > Код</td>
	<td class="inv_card1" width='200' >Найменування (як воно є)</td>
	<td class="inv_card1" width='50' > Серійний номер </td>
	<td class="inv_card1" width='20' >  Кількість </td>
	<td class="inv_card1" width='90' > ціна стар</td>
	<td class="inv_card1" width='20' > Введено</td>

</TR>


<?php
//Экспорт екселя
$_SESSION['to_excel']="
<TABLE  width='100%' border=1>
<font size=9>
<TR >
	<td  width='90' > № Ауд</td>
	<td  width='100' > Інв номер</td>
	<td  width='250' > Найменування цінностей (по бухг)</td>
	<td  width='90' > Код</td>
	<td  width='250' >Найменування (як воно є)</td>
	<td  width='70' > Серійний номер </td>
	<td  width='50' >  Кількість </td>
	<td  width='100' > ціна стар</td>
	<td  width='100' > Введено</td>
</TR>";

//Если страница не указана по умолчанию 1 страница
if(!$_GET['page']){
$_GET['page']=1;
}
//
$sql="SELECT * FROM all_inventory where item_type in (1,2) ";  
$sql5 ="select count(*) from all_inventory where item_type<>1 ";
//Фільтри
if ($_SESSION['inv_numb_filter']){
$sql.=" and inv_numb like '".$_SESSION['inv_numb_filter']."%'";
$sql5.=" and inv_numb like '".$_SESSION['inv_numb_filter']."%'";
};
if ($_SESSION['auditory']){
$sql.=" and auditory=".$_SESSION['auditory'];
$sql5.=" and auditory=".$_SESSION['auditory'];
};
if ($_SESSION['status']){
$sql.=" and status=".$_SESSION['status'];
$sql5.=" and status=".$_SESSION['status'];
};

if ($_SESSION['name_filter']){
$sql.=" and item_name like '".$_SESSION['name_filter']."%'";
$sql5.=" and item_name like '".$_SESSION['name_filter']."%'";
};

//
$process5=mysql_query($sql5, $db);
$count = mysql_fetch_array($process5);
//Получаем целочисленное значение страниц
$count_page=ceil($count[0]/$_SESSION['count_for_page']);
//берем старторвый номер для sql запроса страниц
$start_number=($_GET['page']-1)*$_SESSION['count_for_page'];

if ($count_page>1  && ($_GET[page]!='all')){
$sql.=" LIMIT ".$start_number.",  ".$_SESSION['count_for_page']." ";
}
//echo $sql;
$process=mysql_query($sql, $db);
$i=1;
$j=1;
while ($row = mysql_fetch_array($process, $i)){

echo "<TR >";
$sql2="SELECT auditory_name FROM auditories where auditory_id=".$row[auditory];  
    $process2=mysql_query($sql2, $db);
	$row2 = mysql_fetch_array($process2);
	echo "<td class=\"inv_card1\" width='20'> $row2[auditory_name] </td>";
	echo "<td class=\"inv_card1_l\" width='50' > $row[inv_numb] </td>";
	echo "<td class=\"inv_card1_l\" width='200' >  $row[item_name] </td>";
	echo "<td class=\"inv_card1\" width='4%' >  $row[code]</td>";
	echo "<td class=\"inv_card1_l\" width='200' > $row[another_name] </td>";
	echo "<td class=\"inv_card1\" width='90' > $row[sn_internal]</td>";
	echo "<td class=\"inv_card1_r\" width='20'> $row[count] </td>";
	echo "<td class=\"inv_card1_r\" width='90'>".number_format($row[one_cost], 2, ',', '')."</td>";
	echo "<td class=\"inv_card1\" width='20'>$row[date_open] </td>";
	
echo "</TR>";

$_SESSION['to_excel'].="<TR >
	 <td   width='20'> $row2[auditory_name] </td> 
	 <td   width='50' > $row[inv_numb] </td> 
	 <td   width='200' >  $row[item_name] </td> 
	 <td   width='4%' >  $row[code]</td> 
	 <td   width='200' > $row[another_name] </td> 
	 <td   width='90' > $row[sn_internal]</td> 
	 <td   width='20'> $row[count] </td> 
	 <td   width='90'>".number_format($row[one_cost], 2, ',', '')."</td> 
	 <td   width='20'>$row[date_open] </td> 
</TR>"; 

$j++;
}
?>
</table>
</form>
<?php
if ($count_page>1){
	echo "<center>".$texts[pages]." ";
	if ($_GET[page]!='all'){
	echo "<a href=".$_SERVER['PHP_SELF']."?page=all>".$texts[all_pages]."</a> ";
	}
	else echo $texts[all_pages]." ";
	for ($i=1;$i<=$count_page;$i++){
	if ($_GET[page]!=$i){
		echo "<a href=".$_SERVER['PHP_SELF']."?page=".$i.">$i</a> ";
		}
	else echo "$i ";
	}
}
echo "</center>";
include ('footer.php');

?>